<template>
  <!-- QC工程图 -->
  <p-card :bordered="false">
    <!-- 查询区域 -->
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <p-form layout="inline" @keyup.enter.native="searchQuery">
        <p-row :gutter="24">
          <p-col :xl="6" :lg="7" :md="8" :sm="24">
            <p-form-item label="QC工程图编码">
              <p-input placeholder="请输入QC工程图编码" v-model="queryParam.qcedCode"></p-input>
            </p-form-item>
          </p-col>
          <p-col :xl="6" :lg="7" :md="8" :sm="24">
            <p-form-item label="QC工程图名称">
              <p-input placeholder="请输入QC工程图名称" v-model="queryParam.qcedName"></p-input>
            </p-form-item>
          </p-col>
          <p-col :xl="6" :lg="7" :md="8" :sm="24">
            <p-form-item label="产品编码">
              <p-input placeholder="产品编码" v-model="queryParam.mcode"></p-input>
            </p-form-item>
          </p-col>
          <p-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <p-button type="primary" @click="searchQuery" icon="search">查询</p-button>
              <p-button
                type="primary"
                @click="searchReset"
                icon="reload"
                style="margin-left: 8px"
              >重置</p-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <p-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </p-col>
        </p-row>
      </p-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <p-button @click="openAddBtn" type="primary" icon="plus">新增</p-button>

      <template v-if="cgButtonList && cgButtonList.length>0" v-for="(item,index) in cgButtonList">
        <p-button
          v-if=" item.optType=='js' && (item.groupTag == null || item.groupTag == '' )"
          :key=" 'cgbtn'+index "
          @click="cgButtonJsHandler(item.buttonCode)"
          type="primary"
          :icon="item.buttonIcon"
        >{{ item.buttonName }}</p-button>
        <p-button
          v-else-if=" item.optType=='action' && (item.groupTag == null || item.groupTag == '' )"
          :key=" 'cgbtn'+index "
          @click="cgButtonActionHandler(item.buttonCode)"
          type="primary"
          :icon="item.buttonIcon"
        >{{ item.buttonName }}</p-button>
      </template>

      <!-- 高级查询区域 -->
      <j-super-query
        :fieldList="fieldList"
        ref="superQueryModal"
        @handleSuperQuery="handleSuperQuery"
      ></j-super-query>

      <p-dropdown v-for="(item,index) in groupTag" :key="index">
        <p-button>
          {{item.name}}
          <p-icon type="down" />
        </p-button>
        <p-menu slot="overlay">
          <template v-for="(items,indexs) in item.data">
            <p-menu-item
              v-if=" items.optType=='js' "
              :key="indexs"
              @click="cgButtonJsHandler(items.buttonCode)"
            >
              <p-icon :type="items.buttonIcon" />
              {{items.buttonName}}
            </p-menu-item>
            <p-menu-item
              v-else-if=" items.optType=='action' "
              :key="indexs"
              @click="cgButtonActionHandler(items.buttonCode)"
            >
              <p-icon :type="items.buttonIcon" />
              {{items.buttonName}}
            </p-menu-item>
          </template>
        </p-menu>
      </p-dropdown>

      <p-dropdown v-if="selectedRowKeys.length > 0">
        <p-menu slot="overlay">
          <p-menu-item key="1" @click="batchDel">
            <p-icon type="delete" />删除
          </p-menu-item>
        </p-menu>
        <p-button style="margin-left: 8px">
          批量操作
          <p-icon type="down" />
        </p-button>
      </p-dropdown>
    </div>
    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>

        <span style="float:right;">
          <a @click="handleExportXls('QC工程图')">
            <p-icon type="download" />导出
          </a>
          <p-divider type="vertical" />
          <p-upload
            name="file"
            :showUploadList="false"
            :multiple="false"
            :headers="tokenHeader"
            :action="importExcelUrl"
            @change="handleImportExcel"
          >
            <a>
              <p-icon type="import" />导入
            </a>
          </p-upload>
          <p-divider type="vertical" />
          <a @click="loadData()">
            <p-icon type="sync" />刷新
          </a>
          <p-divider type="vertical" />
          <p-popover title="自定义列" trigger="click" placement="leftBottom" :overlay-style="getWidth">
            <template slot="content">
              <p-checkbox-group
                @change="onColSettingsChange"
                v-model="settingColumns"
                :defaultValue="settingColumns"
              >
                <p-row>
                  <template v-for="(item,index) in defColumns">
                    <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                      <p-col :span="12">
                        <p-checkbox :value="item.dataIndex">{{ item.title }}</p-checkbox>
                      </p-col>
                    </template>
                  </template>
                </p-row>
              </p-checkbox-group>
            </template>
            <a>
              <p-icon type="setting" />自定义列
            </a>
          </p-popover>
        </span>
      </div>

      <p-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :scroll="tableScroll"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange,}"
        :customRow="clickThenSelect"
        :rowClassName="setRowClassName"
        @change="handleTableChange"
      >
        <template slot="productDetail" slot-scope="text,record">
          <p-icon type="plus" @click="openProductModal(record)"/>
        </template>

        <template slot="basicDetail" slot-scope="text,record">
          <p-icon type="form" @click="openBasicDetailModal(record)"/>
        </template>




        <template slot="qcedCode" slot-scope="text,record">
          <a @click="openAllInfoBtn(record)">{{text}}</a>
        </template>

         <template slot="status" slot-scope="text, record">
           <!--<p-tag v-if="text==1"  ><p-icon type="clock-circle" />待审</p-tag>-->
           <p-tag v-if="text==1" color="green"><p-icon type="check-circle" />生效</p-tag>
           <p-tag v-else-if="text==2" color="red"><p-icon type="close-circle" />失效</p-tag>
           <p-tag v-else-if="text==3" ><p-icon  />新增</p-tag>
         </template>


        <span slot="action" slot-scope="text, record">
          <a @click="openEditBtn(record)">编辑</a>

          <p-divider type="vertical" />
          <p-dropdown>
            <a class="ant-dropdown-link">
              更多
              <p-icon type="down" />
            </a>
            <p-menu slot="overlay">
              <p-menu-item>
                <p-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </p-popconfirm>
              </p-menu-item>
              <template
                v-if="cgButtonLinkList && cgButtonLinkList.length>0"
                v-for="(btnItem,btnIndex) in cgButtonLinkList"
              >
                <p-menu-item :key=" 'cgbtnLink'+btnIndex " v-if="showLinkButton(btnItem,record)">
                  <a
                    href="javascript:void(0);"
                    @click="cgButtonLinkHandler(record,btnItem.buttonCode,btnItem.optType)"
                  >
                    <p-icon v-if="btnItem.buttonIcon" :type="btnItem.buttonIcon" />
                    {{ btnItem.buttonName }}
                  </a>
                </p-menu-item>
              </template>
            </p-menu>
          </p-dropdown>
        </span>
      </p-table>
    </div>




    <mesQcEngineeringDrawing-modal ref="modalForm" :EnhanceJS="EnhanceJS" @ok="modalFormOk"></mesQcEngineeringDrawing-modal>


    <p-modal v-model="detailVisible" title="明细编辑" :width="800" @ok="detailEditOk">
      <p-row :gutter="24"  >
        <p-form-model
                ref="ruleForm"
                :model="editingRow"
                :rules="rules"
                :label-col="labelCol" :wrapper-col="wrapperCol"
        >
         <!-- <p-form-model-item label="一级工序" prop="processOneName">
            <p-input v-model="editingRow.processOneName" />
          </p-form-model-item>-->


          <p-col :span="24" >
            <p-form-model-item label="一级工序" prop="processOne">
              <p-col :span="18" >
                <p-select
                        v-if="!dEditOnePI"
                        show-search
                        :value="editingRow.processOneName"
                        placeholder="可输入一级工序模糊搜索"
                        :default-active-first-option="false"
                        :dropdownMatchSelectWidth="false"
                        :show-arrow="false"
                        :filter-option="false"
                        :not-found-content="null"
                        @search="queryAllFirstProcess"
                >
                  <div slot="dropdownRender" >
                    <p-table
                            :columns="processTableColumns"
                            :data-source="processOneList"
                            :pagination="false"
                            :customRow="firstProcessSelect2"
                            bordered
                            :scroll="{ x: 500, y: 300 }"
                    >
                    </p-table>
                  </div>

                </p-select>
                <p-input v-if="dEditOnePI" v-model="editingRow.processOneName" />
              </p-col>



              <p-col :span="5" >
                <p-button style="margin-left: 5px" @click="dEditOnePIBtnClick">
                  {{dEditOnePIBtnText}}
                </p-button>
              </p-col>


            </p-form-model-item>
          </p-col>

          <p-col :span="24" >
            <p-form-model-item label="一级工序编码" prop="processOneCode">
              <p-input v-model="editingRow.processOneCode" :disabled="!dEditOnePI"/>
            </p-form-model-item>

          </p-col>

          <p-col :span="24" >
            <p-form-model-item label="二级工序" prop="processTwoName">
              <!--<p-input v-model="editingRow.processTwoName" />-->

              <p-col :span="18" >
                <p-select
                        v-if="!dEditTwoPI"
                        show-search
                        :value="editingRow.processTwoName"
                        placeholder="可输入二级工序模糊搜索"
                        :default-active-first-option="false"
                        :dropdownMatchSelectWidth="false"
                        :show-arrow="false"
                        :filter-option="false"
                        :not-found-content="null"
                        @search="queryAllSecondProcess"
                >
                  <div slot="dropdownRender" >
                    <p-table
                            :columns="processTableColumns"
                            :data-source="processTwoList"
                            :pagination="false"
                            :customRow="SecondProcessSelect2"
                            bordered
                            :scroll="{ x: 500, y: 300 }"
                    >
                    </p-table>
                  </div>

                </p-select>
                <p-input v-if="dEditTwoPI" v-model="editingRow.processTwoName" />
              </p-col>



              <p-col :span="5" >
                <p-button style="margin-left: 5px" @click="dEditTwoPIBtnClick">
                  {{dEditTwoPIBtnText}}
                </p-button>
              </p-col>

            </p-form-model-item>


          </p-col>
          <p-col :span="24" >
            <p-form-model-item label="二级工序编码" prop="processTwoCode">
              <p-input v-model="editingRow.processTwoCode" :disabled="!dEditTwoPI"/>
            </p-form-model-item>
          </p-col>
          <p-col :span="24" >
            <p-form-model-item label="检验项目" prop="inspectProject">
              <p-input v-model="editingRow.inspectProject" />
            </p-form-model-item>
          </p-col>
          <p-col :span="24" >
            <p-form-model-item label="检验标准" prop="inspectStandard">
              <p-input v-model="editingRow.inspectStandard" />
            </p-form-model-item>
          </p-col>

          <p-col :span="24" >
            <p-form-model-item label="检验手段" prop="inspectMethod">
              <p-select v-model="editingRow.inspectMethod" placeholder="请选择项目类型" >
                <p-select-option
                        v-for="(item,index) in methodList"
                        :key="index"
                        :value="item.value"
                >{{item.title}}</p-select-option>
              </p-select>
            </p-form-model-item>
          </p-col>
  <!--        <p-form-model-item label="检验手段" prop="inspectMethod">
            <p-input v-model="editingRow.inspectMethod" />
          </p-form-model-item>-->

          <p-col :span="24" >
            <p-form-model-item label="检验频次" prop="inspectFrequency">
              <p-input v-model="editingRow.inspectFrequency" />
            </p-form-model-item>
          </p-col>
          <p-col :span="24" >
            <p-form-model-item label="指导文件" prop="policyFile">
              <p-input v-model="editingRow.policyFile" />
            </p-form-model-item>
          </p-col>
          <p-col :span="24" >
            <p-form-model-item label="记录报表" prop="recordReport">
              <p-input v-model="editingRow.recordReport" />
            </p-form-model-item>
          </p-col>
          <p-col :span="24" >
            <p-form-model-item label="异常处置方式" prop="exceptionDmethod">
              <p-input v-model="editingRow.exceptionDmethod" />
            </p-form-model-item>
          </p-col>
          <p-col :span="24" >
            <p-form-model-item label="备注" prop="remark">
              <p-input v-model="editingRow.remark" />
            </p-form-model-item>
          </p-col>
        </p-form-model>

      </p-row>
    </p-modal>



    <p-modal v-model="productModalVisible" title="产品/物料明细"  :width="1300"   :footer="null">
      <p-row :gutter="24"  >
        <p-col :span="7" >
          <p-button type="primary" style="margin-right: 5px" @click="openAddPdBtn">新增</p-button>

          <p-popconfirm  v-if="productSelectRowKeys.length>0" title="确定删除吗?" @confirm="() => deleteProductRows()">
            <p-button  type="danger">删除</p-button>
          </p-popconfirm>


        </p-col>
        <p-col :span="7" >
          <p-input v-model="productSearchStr" placeholder="产品/物料编码/名称" @change="queryProductDetailList"/>
        </p-col>
        <p-col :span="2" >
        </p-col>

      </p-row>

      <p-table

              :columns="productTableColumns"
              :data-source="productTableData"
              class="components-table-demo-nested"
              bordered
              style="margin-top:10px;"
              :rowSelection="{selectedRowKeys: productSelectRowKeys, onChange: productOnSelectChange,}"
      >

        <template slot="edit" slot-scope="text,record">
          <a @click="openProductEditBtn(record)">编辑</a>
        </template>

      </p-table>


    </p-modal>

    <p-modal v-model="pdSmallModalVisible" :title="pdSmallModalTitle" :maskClosable="false" :width="800"   :footer="null">
      <p-form-model
              ref="ruleForm"
              :model="pdForm"
              :label-col="labelCol" :wrapper-col="wrapperCol"
      >
        <p-form-model-item label="产品/物料编码" prop="mid">
          <p-select
                  show-search
                  :value="pdForm.mcode"
                  placeholder="可输入物料编码搜索"
                  :default-active-first-option="false"
                  :show-arrow="false"
                  :filter-option="false"
                  :not-found-content="null"
                  @search="productSearch"
          >
            <div slot="dropdownRender" >
              <p-table
                      :columns="pruductSmallColumns"
                      :data-source="productList"
                      :pagination="false"
                      :customRow="productChange2"
                      bordered
                      :scroll="{ x: 500, y: 300 }"
              >
              </p-table>
            </div>


          </p-select>
        </p-form-model-item>
        <p-form-model-item label="产品/物料名称" prop="mname">
          <p-input v-model="pdForm.mname"/>
        </p-form-model-item>


      </p-form-model>

      <p-row style="text-align: center">
        <p-button type="primary" style="margin-right: 8px" @click="saveProductDetail" >保存</p-button>
        <p-button @click="closeProductModal">取消</p-button>
      </p-row>


    </p-modal>


    <p-modal v-model="pModalVisible" :title="pTitle" :width="800" @ok="pModalOk">
      <p-form-model
              ref="ruleForm"
              :model="form"
              :rules="rules"
              :label-col="labelCol" :wrapper-col="wrapperCol"
      >

        <p-row :gutter="24" >

          <p-col :span="24" >
            <p-form-model-item label="QC工程图编码" prop="qcedCode">
              <p-input v-model="form.qcedCode" readOnly/>
            </p-form-model-item>
          </p-col>

          <p-col :span="24" >
            <p-form-model-item label="QC工程图名称" prop="qcedName">
              <p-input v-model="form.qcedName" :disabled="currentState==2&&(form.status==1||form.status==2)"/>
            </p-form-model-item>
          </p-col>

          <p-col :span="24" >
            <p-form-model-item label="版本" prop="version">
              <p-input v-model="form.version" disabled/>
            </p-form-model-item>
          </p-col>

          <p-col :span="24" >
          <p-form-model-item label="状态" prop="status">
            <p-radio-group v-model="form.status" >

              <p-radio :value="1" :disabled="currentState==1">
                生效
              </p-radio>
              <p-radio :value="2" >
                失效
              </p-radio>
            </p-radio-group>
          </p-form-model-item>
          </p-col>

        </p-row>



      </p-form-model>


    </p-modal>


    <p-modal v-model="detailAddModalVisible" title="明细新增" :width="850" @ok="detailAdd"  :maskClosable="false">
      <p-row :gutter="24"  >
        <p-form-model :model="detailAddForm" :label-col="labelCol" :wrapper-col="wrapperCol">
          <p-col :span="24" >
            <p-form-model-item label="一级工序" prop="processOne">
              <p-col :span="18" >
                <p-select
                        v-if="!dAddOnePI"
                        show-search
                        :value="detailAddForm.processOneName"
                        placeholder="可输入一级工序模糊搜索"
                        :default-active-first-option="false"
                        :dropdownMatchSelectWidth="false"
                        :show-arrow="false"
                        :filter-option="false"
                        :not-found-content="null"
                        @search="queryAllFirstProcess"
                >
                  <div slot="dropdownRender" >
                    <p-table
                            :columns="processTableColumns"
                            :data-source="processOneList"
                            :pagination="false"
                            :customRow="firstProcessSelect"
                            bordered
                            :scroll="{ x: 500, y: 300 }"
                    >
                    </p-table>
                  </div>

                </p-select>
                <p-input v-if="dAddOnePI" v-model="detailAddForm.processOneName" />
              </p-col>



              <p-col :span="5" >
                <p-button style="margin-left: 5px" @click="dAddOnePIBtnClick">
                  {{dAddOnePIBtnText}}
                </p-button>
              </p-col>


            </p-form-model-item>
          </p-col>

          <p-col :span="24" >
            <p-form-model-item label="一级工序编码" prop="processOne">
              <p-input v-model="detailAddForm.processOneCode" :disabled="!dAddOnePI"/>
            </p-form-model-item>
          </p-col>

          <p-col :span="24" >

            <p-form-model-item label="二级工序" prop="processTwo">
             <!-- <p-input v-model="detailAddForm.processTwoName" />-->

              <p-col :span="18" >
                <p-select
                        v-if="!dAddTwoPI"
                        show-search
                        :value="detailAddForm.processTwoName"
                        placeholder="可输入二级工序模糊搜索"
                        :default-active-first-option="false"
                        :dropdownMatchSelectWidth="false"
                        :show-arrow="false"
                        :filter-option="false"
                        :not-found-content="null"
                        @search="queryAllSecondProcess"
                >
                  <div slot="dropdownRender" >
                    <p-table
                            :columns="processTableColumns"
                            :data-source="processTwoList"
                            :pagination="false"
                            :customRow="SecondProcessSelect"
                            bordered
                            :scroll="{ x: 500, y: 300 }"
                    >
                    </p-table>
                  </div>

                </p-select>
                <p-input v-if="dAddTwoPI" v-model="detailAddForm.processTwoName" />
              </p-col>



              <p-col :span="5" >
                <p-button style="margin-left: 5px" @click="dAddTwoPIBtnClick">
                  {{dAddTwoPIBtnText}}
                </p-button>
              </p-col>
            </p-form-model-item>
          </p-col>

          <p-col :span="24" >
            <p-form-model-item label="二级工序编码" prop="processOne">
              <p-input v-model="detailAddForm.processTwoCode" :disabled="!dAddTwoPI"/>
            </p-form-model-item>
          </p-col>

          <p-col :span="24" >
            <p-form-model-item label="检验项目" prop="processOne">
              <p-input v-model="detailAddForm.inspectProject"/>
            </p-form-model-item>
          </p-col>

          <p-col :span="24" >
            <p-form-model-item label="检验标准" prop="processOne">
              <p-input v-model="detailAddForm.inspectStandard"/>
            </p-form-model-item>
          </p-col>

          <p-col :span="24" >
            <p-form-model-item label="检验手段" prop="inspectMethod">
              <p-select v-model="detailAddForm.inspectMethod" placeholder="请选择项目类型" >
                <p-select-option
                        v-for="(item,index) in methodList"
                        :key="index"
                        :value="item.value"
                >{{item.title}}</p-select-option>
              </p-select>
            </p-form-model-item>
          </p-col>
<!--          <p-col :span="24" >
            <p-form-model-item label="检验手段" prop="processOne">
              <p-input v-model="detailAddForm.inspectMethod"/>
            </p-form-model-item>
          </p-col>-->

          <p-col :span="24" >
            <p-form-model-item label="检验频次" prop="processOne">
              <p-input v-model="detailAddForm.inspectFrequency"/>
            </p-form-model-item>
          </p-col>

          <p-col :span="24" >
            <p-form-model-item label="指导文件" prop="processOne">
              <p-input v-model="detailAddForm.policyFile"/>
            </p-form-model-item>
          </p-col>

          <p-col :span="24" >
            <p-form-model-item label="记录报表" prop="processOne">
              <p-input v-model="detailAddForm.recordReport"/>
            </p-form-model-item>
          </p-col>

          <p-col :span="24" >
            <p-form-model-item label="异常处置方式" prop="processOne">
              <p-input v-model="detailAddForm.exceptionDmethod"/>
            </p-form-model-item>
          </p-col>
          <p-col :span="24" >
            <p-form-model-item label="备注" prop="processOne">
              <p-input v-model="detailAddForm.remark"/>
            </p-form-model-item>
          </p-col>

        </p-form-model>
      </p-row>

    </p-modal>

    <p-modal v-model="basicDetailModalVisible" title="明细" :width="1300" @ok="basicDetailModalOk" :footer="null" :maskClosable="false">

      <p-row :gutter="24"  v-if="templateTableData.length==0" >
        <p-col :span="10" >
          <p-form-model :model="templateForm" :label-col="labelCol" :wrapper-col="wrapperCol">



            <p-form-model-item label="参考产品/物料编码" prop="mid">
              <p-select
                      show-search
                      :value="templateForm.mcode"
                      placeholder="可输入物料编码搜索"
                      :default-active-first-option="false"
                      :dropdownMatchSelectWidth="false"
                      :show-arrow="false"
                      :filter-option="false"
                      :not-found-content="null"
                      @search="productSearch"
              >
                <div slot="dropdownRender" >
                  <p-table
                          :columns="pruductSmallColumns"
                          :data-source="productList"
                          :pagination="false"
                          :customRow="productChange3"
                          bordered
                          :scroll="{ x: 500, y: 300 }"
                  >
                  </p-table>
                </div>

              </p-select>
            </p-form-model-item>
          </p-form-model>


        </p-col>

        <p-col :span="10" >
          <p-form-model :model="templateForm" :label-col="labelCol" :wrapper-col="wrapperCol">
            <p-form-model-item label="参考产品/物料名称 ">
              <p-input v-model="templateForm.mname" disabled/>
            </p-form-model-item>
          </p-form-model>
        </p-col>




        <p-col :span="4" >
          <p-button type="primary" @click="queryOtherData">确定</p-button>
        </p-col>

      </p-row>

      <p-row :gutter="24"  >
        <p-col :span="18" >
          <p-button  type="primary"  style="margin-right: 5px" @click="openTemplateAddBtn">新增</p-button>

          <p-popconfirm v-if="templateSelectRowKeys.length>0" title="确定删除吗?" @confirm="() => deleteSelectTemplate()">
            <p-button  type="danger">删除</p-button>
          </p-popconfirm>

        </p-col>
        <p-col :span="3" >

        </p-col>
        <p-col :span="3" >

        </p-col>
      </p-row>

      <p-table

              :columns="detailColumns"
              :data-source="templateTableData"
              class="components-table-demo-nested"
              :scroll="tableScroll2"
              :loading="loading2"
              bordered
              style="margin-top:10px;"
              :rowSelection="{selectedRowKeys: templateSelectRowKeys, onChange: templateOnSelectChange,}"
      >

        <template slot="edit" slot-scope="text,record">
          <a @click="openDetailEditBtn(record)">编辑</a>
        </template>

      </p-table>

    </p-modal>


    <p-drawer
            title="详情"
            placement="right"
            :closable="false"
            :width="900"
            :visible="allInfoVisible"
            @close="closeDetailBtn"
    >

      <p-divider orientation="left">
        主信息
      </p-divider>

      <p-descriptions  bordered size="small">
        <p-descriptions-item label="QC工程图编码">
          {{de.qcedCode}}
        </p-descriptions-item>

        <p-descriptions-item label="QC工程图名称" :span="2">
          {{de.qcedName}}
        </p-descriptions-item>

        <p-descriptions-item label="版本">
          {{de.version}}
        </p-descriptions-item>

        <p-descriptions-item label="状态" :span="2">
          <p-tag v-if="de.status==1" color="green"><p-icon type="check-circle" />生效</p-tag>
          <p-tag v-else-if="de.status==2" color="red"><p-icon type="close-circle" />失效</p-tag>
        </p-descriptions-item>

        <p-descriptions-item label="创建者" :span="2">
          {{de.createBy}}
        </p-descriptions-item>
        <p-descriptions-item label="创建日期">
          {{de.createTime?dayjs(de.createTime).format('YYYY-MM-DD'):''}}
        </p-descriptions-item>

        <p-descriptions-item label="修改者" :span="2">
          {{de.updateBy}}
        </p-descriptions-item>
        <p-descriptions-item label="更新日期">
          {{de.updateTime?dayjs(de.updateTime).format('YYYY-MM-DD'):''}}
        </p-descriptions-item>
      </p-descriptions>

      <p-divider orientation="left">
        其他信息
      </p-divider>

      <p-collapse v-model="activeKey">
        <p-collapse-panel key="1" header="产品/物料明细">
          <p-table

                  :columns="productTableColumns1"
                  :data-source="de.qualityFileProductDetailList"
                  class="components-table-demo-nested"
                  bordered
                  style="margin-top:10px;"
          >
          </p-table>
        </p-collapse-panel>

        <p-collapse-panel key="2" header="明细">
          <p-table

                  :columns="detailColumns1"
                  :data-source="de.qcEdDetailList"
                  class="components-table-demo-nested"
                  :scroll="tableScroll3"
                  bordered
                  style="margin-top:10px;"
          >

          </p-table>
        </p-collapse-panel>

      </p-collapse>



    </p-drawer>


    <!-- 弹出窗 -->
    <Fx-compontens-modal
      @ok="modalFormOk"
      ref="modalCompon"
      :getList="queryInfo"
      :title="title"
      :dictOptions="dictOptions"
    ></Fx-compontens-modal>
  </p-card>
</template>

<script>
import { JeecgListMixin } from "@/mixins/JeecgListMixin";
import { api } from "@/api/manage";
import JSuperQuery from "@/components/jeecg/JSuperQuery.vue";
import { filterObj } from "@/utils/util";
import MesQcEngineeringDrawingModal from "./modules/MesQcEngineeringDrawingModal";
import Vue from "vue";
import  dayjs   from 'dayjs';
import MesQcEdDetailList from "./MesQcEdDetailList";
import {
  initDictOptions,
  filterMultiDictText,
} from "@/components/dict/JDictSelectUtil";
import MesQcQualityFileProductDetailList from "./MesQcQualityFileProductDetailList";
import ButtonExpHandler from "@/components/jeecgbiz/modules/ButtonExpHandler";
import { postAction, getAction, deleteAction,putAction } from "@/api/manage";
import FxCompontensModal from "@/components/jeecgbiz/FxCompontensModal";

//高级查询modal需要参数
const superQueryFieldList = [
  {
    value: "qcedCode",
    text: "QC工程图编码",
    type: "string",
  },
  {
    value: "qcedName",
    text: "QC工程图名称",
    type: "string",
  },
  {
    value: "version",
    text: "版本",
    type: "string",
  },
  {
    value: "createBy",
    text: "创建人",
    type: "string",
  },
  {
    value: "createTime",
    text: "创建日期",
    type: "Date",
  },
  {
    value: "updateBy",
    text: "更新人",
    type: "string",
  },
  {
    value: "updateTime",
    text: "更新日期",
    type: "Date",
  },
  {
    value: "status",
    text: "状态",
    type: "select",
    dictCode: "mes_audit_status",
  },
];

export default {
  name: "MesQcEngineeringDrawingList",
  mixins: [JeecgListMixin],
  components: {
    JSuperQuery,
    MesQcEdDetailList,
    FxCompontensModal,
    MesQcQualityFileProductDetailList,
    MesQcEngineeringDrawingModal,
  },
  data() {
    return {
      fieldList: superQueryFieldList,
      superQueryFlag: false,
      superQueryParams: "",
      description: "QC工程图管理页面",
      EnhanceJS: "",
      cgButtonLinkList: [],
      cgButtonList: [],

      templateSelectRowKeys:[],
      templateSelectRows:[],


      pruductSmallColumns:[
        {
          title: '产品/物料编码',
          align: 'center',
          dataIndex: 'mcode',
        },
        {
          title: '产品/物料名称',
          align: 'center',
          dataIndex: 'mname',
        },
      ],

      pdForm:{
        mid:'',
        mcode:'',
        mname:'',
      },

      currentBasicId:0,

      pModalVisible:false,
      basicDetailModalVisible:false,

      detailAddModalVisible:false,

      dEditOnePI:true,
      dEditOnePIBtnText:'返回下拉选择',

      dEditTwoPI:true,
      dEditTwoPIBtnText:'返回下拉选择',

      dAddOnePI:false,
      dAddOnePIBtnText:'自定义编辑',

      dAddTwoPI:false,
      dAddTwoPIBtnText:'自定义编辑',

      detailAddForm:{
        processOneName:'',
        processOneCode:'',
        processOneId:'',
        processTwoId:'',
        processTwoCode:'',
        processTwoName:'',
        inspectProject:'',
        inspectStandard:'',
        inspectMethod:'',
        inspectFrequency:'',
        policyFile:'',
        recordReport:'',
        exceptionDmethod:'',
        remark:'',

      },

      templateForm:{
        mcode:'',
        mname:'',
      },

      templateTableData:[],

      de:{},
      activeKey:['1'],

      pTitle:'',
      labelCol: { span: 6 },
      wrapperCol: { span: 16 },
      currentState:1,

      productSelectRowKeys:[],
      productSelectRows:[],

      editP:{},
      editingRow:{

      },

      detailVisible:false,
      allInfoVisible:false,

      form: {
        qcedCode:'',
        qcedName:'',
        version:'V1.0',
      },
      rules: {
        qcedName: [{ required: true, message: '请输入QC工程图名称', trigger: 'change' }],
      },
      methodList:[],
      methodMap: [],

      qcedCode:'',

      productModalVisible:false,
      productSearchStr:'',
      pdSmallModalVisible:false,
      pdSmallModalTitle:'',
      pdCurrentState:1,

      productTableColumns:[
        {
          title: '产品/物料编码',
          align: 'center',
          dataIndex: 'mcode',
        },
        {
          title: '产品/物料名称',
          align: 'center',
          dataIndex: 'mname',
        },

        {
          title: '创建者',
          align: 'center',
          dataIndex: 'createBy',
        },
        {
          title: '创建日期',
          align: 'center',
          dataIndex: 'createTime',
        },
        {
          title: '修改者',
          align: 'center',
          dataIndex: 'updateBy',
        },
        {
          title: '修改日期',
          align: 'center',
          dataIndex: 'updateTime',
        },
        {
          title: '编辑',
          align: 'center',
          dataIndex: 'id',
          scopedSlots: { customRender: 'edit' },
        },
      ],

      productTableColumns1:[
        {
          title: '产品/物料编码',
          align: 'center',
          dataIndex: 'mcode',
        },
        {
          title: '产品/物料名称',
          align: 'center',
          dataIndex: 'mname',
        },

        {
          title: '创建者',
          align: 'center',
          dataIndex: 'createBy',
        },
        {
          title: '创建日期',
          align: 'center',
          dataIndex: 'createTime',
          customRender:(text)=>{
            if(!text){
              return '';
            }else{
              return dayjs(text).format('YYYY-MM-DD')
            }
          }
        },
        {
          title: '修改者',
          align: 'center',
          dataIndex: 'updateBy',
        },
        {
          title: '修改日期',
          align: 'center',
          dataIndex: 'updateTime',
          customRender:(text)=>{
            if(!text){
              return '';
            }else{
              return dayjs(text).format('YYYY-MM-DD')
            }
          }
        },

      ],
      productTableData:[
      ],

      rowId:0,
      ckMid:'',
      ckMcode:'',
      ckMname:'',

      loading2:false,

      detailColumns:[
        {
          title: "一级工序",
          width:150,
          align: "center",
          dataIndex: "processOneName",
          fixed:'left'
        },
        {
          title: "一级工序编码",
          width:120,
          align: "center",
          dataIndex: "processOneCode",
          fixed:'left'
        },
        {
          title: "二级工序",
          width:150,
          align: "center",
          dataIndex: "processTwoName",
          fixed:'left'
        },
        {
          title: "二级工序编码",
          width:120,
          align: "center",
          dataIndex: "processTwoCode",
          fixed:'left'
        },
        {
          title: "检验项目",
          width:150,
          align: "center",
          dataIndex: "inspectProject",
        },
        {
          title: "检验标准",
          width:150,
          align: "center",
          dataIndex: "inspectStandard",
        },
        {
          title: "检验手段",
          width:150,
          align: "center",
          dataIndex: "inspectMethod",
          customRender:(text)=>{
            if(!text){
              return "";
            }else{
              if(this.inspectMethodMap[text]){
                return this.inspectMethodMap[text].title;
              }
              return  "";
            }
          }
        },
        {
          title: "检验频次",
          width:180,
          align: "center",
          dataIndex: "inspectFrequency",
          scopedSlots: { customRender: "inspectFrequency" },
        },
        {
          title: "指导文件",
          width:180,
          align: "center",
          dataIndex: "policyFile",
          scopedSlots: { customRender: "policyFile" },
        },
        {
          title: "记录报表",
          width:180,
          align: "center",
          dataIndex: "recordReport",
          scopedSlots: { customRender: "recordReport" },
        },
        {
          title: "异常处置方式",
          width:180,
          align: "center",
          dataIndex: "exceptionDmethod",
          scopedSlots: { customRender: "exceptionDmethod" },
        },
        {
          title: "备注",
          width:180,
          align: "center",
          dataIndex: "remark",
          scopedSlots: { customRender: "remark" },
        },
        {
          title: "编辑",
          width:60,
          fixed:'right',
          align: "center",
          dataIndex: "id",
          scopedSlots: { customRender: "edit" },
        },

      ],

      detailColumns1:[
        {
          title: "一级工序",
          width:100,
          align: "center",
          dataIndex: "processOneName",

        },
        {
          title: "一级工序编码",
          width:70,
          align: "center",
          dataIndex: "processOneCode",

        },
        {
          title: "二级工序",
          width:100,
          align: "center",
          dataIndex: "processTwoName",

        },
        {
          title: "二级工序编码",
          width:70,
          align: "center",
          dataIndex: "processTwoCode",

        },
        {
          title: "检验项目",
          width:100,
          align: "center",
          dataIndex: "inspectProject",
        },
        {
          title: "检验标准",
          width:100,
          align: "center",
          dataIndex: "inspectStandard",
        },
        {
          title: "检验手段",
          width:100,
          align: "center",
          dataIndex: "inspectMethod",
        },
        {
          title: "检验频次",
          width:130,
          align: "center",
          dataIndex: "inspectFrequency",
          scopedSlots: { customRender: "inspectFrequency" },
        },
        {
          title: "指导文件",
          width:130,
          align: "center",
          dataIndex: "policyFile",
          scopedSlots: { customRender: "policyFile" },
        },
        {
          title: "记录报表",
          width:130,
          align: "center",
          dataIndex: "recordReport",
          scopedSlots: { customRender: "recordReport" },
        },
        {
          title: "异常处置方式",
          width:130,
          align: "center",
          dataIndex: "exceptionDmethod",
          scopedSlots: { customRender: "exceptionDmethod" },
        },
        {
          title: "备注",
          width:130,
          align: "center",
          dataIndex: "remark",
          scopedSlots: { customRender: "remark" },
        },


      ],
      detailData:[],
      editingKey:'',


      productList:[],
      productMap:[],

      processOneList:[],
      processTwoList:[],


      processTableColumns:[
        {
          title: '工序名称',
          align: 'center',
          dataIndex: 'processmname',
        },
        {
          title: '工序编码',
          align: 'center',
          dataIndex: 'processmcode',
        }
      ],

      title: "", //存表名
      groupTag: [],
      queryInfo: [],
      code: "",
      // 表头
      columns: [],
      //列设置
      settingColumns: [],
      //列定义
      defColumns: [
        {
          title: "序号",
          dataIndex: "",
          key: "rowIndex",
          width: 50,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          },

        },
        {
          title: '产品/物料明细',
          align: 'center',
          width: 65,
          dataIndex: 'id',
          scopedSlots: { customRender: 'productDetail' },
        },
        {
          title: '明细',
          align: 'center',
          width: 65,
          dataIndex: 'id',
          scopedSlots: { customRender: 'basicDetail' },
        },
        {
          title: "QC工程图编码",
          align: "center",
          dataIndex: "qcedCode",
          scopedSlots: { customRender: "qcedCode" },
        },
        {
          title: "QC工程图名称",
          align: "center",
          dataIndex: "qcedName",
        },
        {
          title: "版本",
          align: "center",
          dataIndex: "version",
        },
        {
          title: "创建人",
          align: "center",
          dataIndex: "createBy",
        },
        {
          title: "创建日期",
          align: "center",
          dataIndex: "createTime",
          customRender: function (text) {
            return !text ? "" : text.length > 10 ? text.substr(0, 10) : text;
          },
        },
        {
          title: "更新人",
          align: "center",
          dataIndex: "updateBy",
        },
        {
          title: "更新日期",
          align: "center",
          dataIndex: "updateTime",
          customRender: function (text) {
            return !text ? "" : text.length > 10 ? text.substr(0, 10) : text;
          },
        },
        {
          title: "状态",
          align: "center",
          dataIndex: "status",
          scopedSlots: { customRender: "status" },
        },
        {
          title: "操作",
          dataIndex: "action",
          align: "center",
          scopedSlots: { customRender: "action" },
        },
      ],
      url: {
        list: "/mes-quality/mesQcEngineeringDrawing/list",
        delete: "/mes-quality/mesQcEngineeringDrawing/delete",
        deleteBatch: "/mes-quality/mesQcEngineeringDrawing/deleteBatch",
        exportXlsUrl: "/mes-quality/mesQcEngineeringDrawing/exportXls",
        importExcelUrl: "/mes-quality/mesQcEngineeringDrawing/importExcel",
        getColumns: "/mes-quality/online/cgform/api/getColumns/",
        buttonAction: "/mes-quality/online/cgform/api/doButton",
      },
      dictOptions: {},
      /* 分页参数 */
      ipagination: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ["10", "20", "50"],
        showTotal: (total, range) => {
          return range[0] + "-" + range[1] + " 共" + total + "条";
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0,
      },
      selectedMainId: "",
    };
  },
  computed: {
    importExcelUrl: function () {
      return `${api.test}${this.url.importExcelUrl}`;
    },
    getWidth: function () {
      if (this.defColumns.length > 14) {
        return { width: "500px" };
      }
    },
    newSelectedMainId: function () {
      if (typeof this.selectedMainId == "number") {
        return this.selectedMainId.toString();
      } else {
        return this.selectedMainId;
      }
    },
    tableScroll: function () {
      if (this.columns.length > 13) {
        return { x: this.columns.length * 150 - 450 };
      }
    },


    tableScroll2: function () {

      return { x: 1950 }

    },
    tableScroll3: function () {

      return { x: 1550 }

    },
  },

  created() {
    this.getMethodList();
    this.initAllOneProcessList('');
    this.initInspectMethodList();
    this.initProductList({});
    this.initQcedCode();
    this.initButtonList();
    this.initColumns();
    this.setdefColumns();
  },

  methods: {


    openTemplateAddBtn(){
      this.detailAddModalVisible = true;

      this.detailAddForm={
        processOneName:'',
                processOneCode:'',
                processOneId:'',
                processTwoId:'',
                processTwoCode:'',
                processTwoName:'',
                inspectProject:'',
                inspectStandard:'',
                inspectMethod:'',
                inspectFrequency:'',
                policyFile:'',
                recordReport:'',
                exceptionDmethod:'',
                remark:'',

      };

      this.dAddOnePI=false;
              this.dAddOnePIBtnText='自定义编辑';

              this.dAddTwoPI=false;
              this.dAddTwoPIBtnText='自定义编辑';
    },

    //封装listToMap
    listToMap(list,name){
      let map = {};
      for(let i in list){
        map[list[i][name]] = list[i];
      }
      return map;
    },

    initAllOneProcessList(keyword){
      getAction('/mes-craft/craft/mesPeDefinition/getAllFirstDef?keyword='+keyword,).then(res=>{
        if(res.success){
          this.processOneList = res.data;
        }
      })
    },
    dayjs,
    queryAllFirstProcess(value){
      this.initAllOneProcessList(value)
    },

    queryAllSecondProcess(value){
      let resultList = [];

      this.processTwoListFirst.forEach(item=>{
        let flag = false;
        if(item.processmcode.indexOf(value)!=-1){
          flag  = true;
        }
        if(item.processmname.indexOf(value)!=-1){
          flag  = true;
        }

        if(flag){
          resultList.push(item);
        }
      })

      this.processTwoList = resultList;
      this.processTwoMap =  this.listToMap(this.processTwoList,'id');
    },

    querySecondProcessList(firstProcessCode){
      if(firstProcessCode&&firstProcessCode!=''){
        getAction('/mes-craft/craft/mesPeDefinition/getAllUnderFirstDef?firstProcessCode='+firstProcessCode).then(res=>{
            if(res.success){
              this.processTwoList = res.data;
              this.processTwoList.forEach(item=>{
                if(item.children){
                  delete item.children
                }
              })
            }
          this.processTwoMap = this.listToMap(this.processTwoList,'id');
          this.processTwoListFirst = this.processTwoList;
          this.processTwoMapFirst = this.processTwoMap;
        })
      }

    },


    deleteSelectTemplate(){
      let result = "";
      this.templateSelectRows.forEach(item=>{
        result = result+item.id+',';
      })
      result = result.substring(0,result.length-1);


      deleteAction('/mes-quality/mesQcEngineeringDrawing/deleteBatchMesQcEdDetail?ids='+result).then(res=>{
        if(res.success){
          this.$message.success("删除成功！");
          this.queryAllInfoById();
          this.templateSelectRowKeys = [];
          this.templateSelectRows = [];
        }else{
          this.$message.warning(res.msg);
        }
      })
    },

    initQcedCode(){
      getAction('/basic-business/sys/fillRule/getFillRule/',{ruleCode:'mes_qc_engineering_rule'}).then(res=>{
        if(res.success){
          this.qcedCode = res.data;
        }
      })
    },

    templateOnSelectChange(selectedRowKeys,selectionRows){
      this.templateSelectRowKeys = selectedRowKeys;
      this.templateSelectRows = selectionRows;
    },

    closeDetailBtn(){
      this.allInfoVisible = false;
    },



    queryOtherData(){
        let mcode   = this.templateForm.mcode;

        if(this.currentBasicId&&this.currentBasicId!=''){
          if(mcode&&mcode!=''){
            getAction('/mes-quality/mesQcEngineeringDrawing/selectDetailByMcode?qcId='+this.currentBasicId+'&mcode='+mcode).then(res=>{
              if(res.success){
                this.$message.success('操作成功！');
                this.queryAllInfoById();
              }else{
                this.$message.warning(res.msg);
              }
            })
          }
        }


    },

    closeProductModal(){
      console.log(11233311)
      this.pdSmallModalVisible = false;
    },

    openProductModal(record){
      this.productModalVisible = true;
      let id = record.id;
      this.currentBasicId = id;
      this.queryProductDetailList();
    },

    openAllInfoBtn(record){
      let id = record.id;

      this.loading2 = true;

      getAction('/mes-quality/mesQcEngineeringDrawing/selectById/'+id).then(res=>{
        if(res.success){
          if(res.data){
            this.de = res.data;
            this.activeKey = ['1'];
            this.allInfoVisible = true;
          }

        }else{
          this.$message.warning(res.msg);
        }
      }).then(res=>{
        this.loading2 = false;
      })

    },


    openBasicDetailModal(record){
      this.basicDetailModalVisible = true;
      let id = record.id;
      this.currentBasicId = id;
      this.templateForm.mcode ='';
      this.templateForm.mname ='';
      this.templateForm.mid = '';
      this.queryAllInfoById();
    },
    getMethodList(){
      getAction('/basic-business/sys/dict/queryDictItemsByCode',{dictCode:'mes_inspect_method'}).then(res=>{
        if(res.success){
          this.methodList = res.data;
          this.methodMap = this.listToMap(this.methodList,'value');
        }
      })
    },
    queryAllInfoById(){
      getAction('/mes-quality/mesQcEngineeringDrawing/selectById/'+this.currentBasicId).then(res=>{
        if(res.success){
          if(res.data){
            this.templateTableData = res.data.qcEdDetailList;
          }

        }else{
          this.$message.warning(res.msg);
        }
      })
    },

    detailEditOk(){
      let data = this.editingRow;

      let flag = true;

      if(data.processOneName==''){
        flag = false;
        this.$message.error("请填写/选择一级工序名称");
      }
      if(data.processOneCode==''){
        flag = false;
        this.$message.error("请填写/选择一级工序编码");
      }else{
        if(data.processTwoCode==""){
          flag = false;
          this.$message.error("请填写/选择二级工序编码");
        }
        if(data.processTwoName==""){
          flag = false;
          this.$message.error("请填写/选择二级工序名称");
        }
      }

      if(flag){
        putAction('/mes-quality/mesQcEngineeringDrawing/editMesQcEdDetail',data).then(res=>{
          if(res.success){
            this.$message.success("编辑成功！")
            this.detailVisible = false;
            this.queryAllInfoById();
          }else{
            this.$message.warning(res.msg);
          }
        })
      }

    },


    queryProductDetailList(){
      let id = this.currentBasicId;
      let productSearchStr = this.productSearchStr;


      getAction('/mes-quality/mesQcEngineeringDrawing/selectByQcEngineeringId?id='+id+'&proNc='+productSearchStr).then(res=>{
        if(res.success){
          this.productTableData = res.data;
          this.productSelectRows=[];
          this.productSelectRowKeys=[];
        }else{
          this.$message.warning(res.msg);
        }
      })
    },

    detailAdd(){
      let data = this.detailAddForm;
      let flag = true;
      if(data.processOneName==''){
        flag = false;
        this.$message.error("请填写/选择一级工序名称");
      }
      if(data.processOneCode==''){
        flag = false;
        this.$message.error("请填写/选择一级工序编码");
      }else{
        if(data.processTwoCode==""){
          flag = false;
          this.$message.error("请填写/选择二级工序编码");
        }
        if(data.processTwoName==""){
          flag = false;
          this.$message.error("请填写/选择二级工序名称");
        }
      }

      if(flag){
        data.qcedId = this.currentBasicId;
        postAction('/mes-quality/mesQcEngineeringDrawing/addMesQcEdDetail',data).then(res=>{
          if(res.success){
            this.$message.success("新增成功！")
            this.detailAddModalVisible = false;
            this.queryAllInfoById();
          }else{
            this.$message.warning(res.msg);
          }
        })

      }

    },

    openAddPdBtn(){
      this.pdSmallModalTitle = '产品/物料明细新增';
      this.pdSmallModalVisible = true;
      this.pdCurrentState = 1;
    },

    productSearch(value){
      this.initProductList({mcode:value+''});
    },

    deleteProductRows(){
      let data = this.productSelectRows;
      let ids = "";
      data.forEach(item=>{
        ids = ids+ item.id+',';
      })
      ids = ids.substring(0,ids.length-1)
      console.log(ids)

      deleteAction('/mes-quality/mesQcEngineeringDrawing/deleteProductDetail', {ids:ids}).then(res=>{
        if(res.success){
          this.$message.success("删除成功！");
          this.productSelectRows=[];
          this.productSelectRowKeys=[];
          this.queryProductDetailList();
        }else{
          this.$message.warning(res.msg);
        }
      })
    },

    saveProductDetail(){
      let flag = true;

      if(this.pdForm.mid==''){
        flag = false;
        this.$message.warning("请选择产品/物料！");
      }

      if(flag){
        if(this.pdCurrentState==1){
          this.productAddOperation();
        }else if(this.pdCurrentState==2){
          this.productEditOperation();
        }
      }

    },

    productEditOperation(){
      let data = this.pdForm;
      let p = this.productEditP;
      p.mid = data.mid;
      p.mcode = data.mcode;
      p.mname = data.mname;

      putAction('/mes-quality/mesQcEngineeringDrawing/editProductDetail',p).then(res=>{
        if(res.success){
          this.pdSmallModalVisible= false;
          this.$message.success("修改成功");
          this.queryProductDetailList();
          this.pdForm.mid = '';
          this.pdForm.mcode = '';
          this.pdForm.mname = '';
          this.initProductList({mcode:''});
        }else{
          this.$message.warning(res.msg);
        }
      })
    },

    productAddOperation(){
      let data = this.pdForm;
      data.mesQcId = this.currentBasicId;

      postAction('/mes-quality/mesQcEngineeringDrawing/addProductDetail',data).then(res=>{
        if(res.success){
          this.pdSmallModalVisible= false;
          this.$message.success("新增成功");
          this.queryProductDetailList();
          this.pdForm.mid = '';
          this.pdForm.mcode = '';
          this.pdForm.mname = '';
          this.initProductList({mcode:''});
        }else{
          this.$message.warning(res.msg);
        }
      })
    },



    productChange2(record){

      return {
        on: {
          click: () => {
            let value = record.id;
            this.pdForm.mcode ='';
            this.pdForm.mname ='';
            this.pdForm.mid = value;
            if(this.productMap[value]){
              this.pdForm.mcode = this.productMap[value].mcode;
              this.pdForm.mname = this.productMap[value].mname;
            }
          },
        },
      };
    },

    dAddTwoPIBtnClick(){

      this.detailAddForm.processTwoId = ''

      if(!this.dAddTwoPI){
        this.dAddTwoPI = true;
        this.dAddTwoPIBtnText = '返回下拉选择';
      }else{
        this.dAddTwoPI = false;
        this.detailAddForm.processTwoName = ''
        this.detailAddForm.processTwoCode = ''
        this.dAddTwoPIBtnText = '自定义编辑';
      }
    },

    dEditTwoPIBtnClick(){

      this.editingRow.processTwoId = ''

      if(!this.dEditTwoPI){
        this.dEditTwoPI = true;
        this.dEditTwoPIBtnText = '返回下拉选择';
      }else{
        this.dEditTwoPI = false;
        this.editingRow.processTwoName = ''
        this.editingRow.processTwoCode = ''
        this.dEditTwoPIBtnText = '自定义编辑';
      }
    },

    dEditOnePIBtnClick(){

      this.editingRow.processTwoId = ''


      this.editingRow.processOneId = ''

      if(!this.dEditOnePI){
        this.dEditOnePI = true;
        this.dEditOnePIBtnText = '返回下拉选择';
      }else{
        this.dEditOnePI = false;
        this.editingRow.processTwoName = ''
        this.editingRow.processTwoCode = ''
        this.editingRow.processOneName = ''
        this.editingRow.processOneCode = ''
        this.dEditOnePIBtnText = '自定义编辑';
      }

    },

    dAddOnePIBtnClick(){

      this.detailAddForm.processTwoId = ''


      this.detailAddForm.processOneId = ''

      if(!this.dAddOnePI){
        this.dAddOnePI = true;
        this.dAddOnePIBtnText = '返回下拉选择';
      }else{
        this.detailAddForm.processTwoName = ''
        this.detailAddForm.processTwoCode = ''
        this.detailAddForm.processOneName = ''
        this.detailAddForm.processOneCode = ''
        this.dAddOnePI = false;
        this.dAddOnePIBtnText = '自定义编辑';
      }

    },
    firstProcessSelect(record){
      return {
        on: {
          click: () => {
            this.detailAddForm.processTwoName = ''
            this.detailAddForm.processTwoCode = ''
            this.detailAddForm.processTwoId = ''

            this.detailAddForm.processOneName = record.processmname
            this.detailAddForm.processOneCode = record.processmcode
            this.detailAddForm.processOneId = record.id

            this.querySecondProcessList(record.processmcode);
          },
        },
      };
    },

    firstProcessSelect2(record){
      return {
        on: {
          click: () => {
            this.editingRow.processTwoName = ''
            this.editingRow.processTwoCode = ''
            this.editingRow.processTwoId = ''

            this.editingRow.processOneName = record.processmname
            this.editingRow.processOneCode = record.processmcode
            this.editingRow.processOneId = record.id

            this.querySecondProcessList(record.processmcode);
          },
        },
      };
    },

    SecondProcessSelect(record){
      return {
        on: {
          click: () => {
            this.detailAddForm.processTwoName = record.processmname
            this.detailAddForm.processTwoCode = record.processmcode
            this.detailAddForm.processTwoId = record.id

          },
        },
      };
    },
    SecondProcessSelect2(record){
      return {
        on: {
          click: () => {
            this.editingRow.processTwoName = record.processmname
            this.editingRow.processTwoCode = record.processmcode
            this.editingRow.processTwoId = record.id

          },
        },
      };
    },

    productChange3(record){

      return {
        on: {
          click: () => {
            let value = record.id;
            this.templateForm.mcode ='';
            this.templateForm.mname ='';
            this.templateForm.mid = value;
            if(this.productMap[value]){
              this.templateForm.mcode = this.productMap[value].mcode;
              this.templateForm.mname = this.productMap[value].mname;
            }
          },
        },
      };
    },

    queryDetailDataByMcode(mcode){


      getAction('/mes-quality/mesQcEngineeringDrawing/selectDetailByMcode?mcode='+mcode).then(res=>{
        if(res.success){
          //detailData
          this.detailData = res.data;
          let key = 1;
          this.detailData.forEach(item=>{
            item.key = key;
              item.editable = false;
            key=key+1;

          })

        }else{
          this.$message.warning(res.msg);
        }
      })
    },

    initProductList(data){
      getAction('/basic-business/auto/baCpinfoMain/queryLimit',data).then(res=>{
        if(res.success){
          this.productList = res.data;
          this.productMap = this.listToMap(this.productList,'id');
        }
      })
    },


    openAddBtn(){
      this.pModalVisible = true;
      this.pTitle = 'QC工程图新增'
      this.currentState=1;
      this.form={
        qcedCode:this.qcedCode,
        qcedName:'',
        version:'V1.0',
        status:2
      }
    },

    openEditBtn(record){
      this.pModalVisible = true;
      this.pTitle = 'QC工程图编辑'
      this.currentState=2;

      this.editP = record;
      console.log(this.editP)
      this.form={
        qcedCode:record.qcedCode,
        qcedName:record.qcedName,
        version:record.version,
        status:record.status,
      }

    },

    productOnSelectChange(selectedRowKeys, selectionRows){
      this.productSelectRowKeys = selectedRowKeys;
      this.productSelectRows = selectionRows;
    },

    pModalOk(){



      this.$refs.ruleForm.validate(valid => {
        if (valid) {
          if(this.currentState==1){
            this.pAddOperation();
          }else if(this.currentState==2){
            this.pEditOperation();
          }
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },


    pAddOperation(){
      let data = this.form;

      postAction('/mes-quality/mesQcEngineeringDrawing/add',data).then(res=>{
        if(res.success){
          this.pModalVisible = false;
          this.$message.success("新增成功!");
          this.initQcedCode();
          this.loadData();
        }else{
          this.$message.warning(res.msg);
        }
      })

    },

    pEditOperation(){
      let data = this.editP;
      console.log(this.editP)
      let record = this.form;
      data.qcedCode=record.qcedCode;
      data.qcedName=record.qcedName;
      data.version=record.version;
     data.status = record.status;

      putAction('/mes-quality/mesQcEngineeringDrawing/edit',data).then(res=>{
        if(res.success){
          this.pModalVisible = false;
          this.$message.success("修改成功！");
          this.loadData();
          this.detailData = [];
          this.form.version = 'V1.0';
          this.form.qcedName = '';
        }else{
          this.$message.warning(res.msg);
          this.loadData();
        }
      })

    },


    openProductEditBtn(record){
      this.pdSmallModalVisible = true;
      this.pdSmallModalTitle = '产品/物料明细编辑';
      this.pdCurrentState = 2;
      this.productEditP = record;
      this.pdForm={
        mid:record.mid,
        mcode:record.mcode,
        mname:record.mname
      }

      this.initProductList({mcode:record.mcode});
    },

    openDetailEditBtn(record){
    /*  this.editingRow = record;
*/
      this.editingRow = JSON.parse(JSON.stringify(record));

      this.detailVisible = true;

      this.dEditOnePI =true;
      this.dEditOnePIBtnText = '返回下拉选择';
      this.dEditTwoPI = true;
      this.dEditTwoPIBtnText= '返回下拉选择';
    },

    initInspectMethodList(){
      getAction('/basic-business/sys/dict/queryDictItemsByCode',{dictCode:'mes_inspect_method'}).then(res=>{
        if(res.success){
          this.inspectMethodList = res.data;
          this.inspectMethodMap = this.listToMap(this.inspectMethodList,'value');
        }
      })
    },

    setdefColumns() {
      if (this.columns.length > 13) {
        let arrLength = this.columns.length - 1;
        this.columns.forEach((item, index) => {
          item["width"] = 130;
        });
        this.columns[arrLength]["fixed"] = "right";
        this.columns[0]["fixed"] = "left";
        this.columns[1]["fixed"] = "left";
      }
    },
    initColumns() {
      //权限过滤（列权限控制时打开，修改第二个参数为授权码前缀）
      //this.defColumns = colAuthFilter(this.defColumns,'testdemo:');

      var key = this.$route.name + ":colsettings";
      let colSettings = Vue.ls.get(key);
      if (colSettings == null || colSettings == undefined) {
        let allSettingColumns = [];
        this.defColumns.forEach(function (item, i, array) {
          allSettingColumns.push(item.dataIndex);
        });
        this.settingColumns = allSettingColumns;
        this.columns = this.defColumns;
      } else {
        this.settingColumns = colSettings;
        const cols = this.defColumns.filter((item) => {
          if (item.key == "rowIndex" || item.dataIndex == "action") {
            return true;
          }
          if (colSettings.includes(item.dataIndex)) {
            return true;
          }
          return false;
        });
        this.columns = cols;
      }
    },
    //列设置更改事件
    onColSettingsChange(checkedValues) {
      var key = this.$route.name + ":colsettings";
      Vue.ls.set(key, checkedValues, 7 * 24 * 60 * 60 * 1000);
      this.settingColumns = checkedValues;
      const cols = this.defColumns.filter((item) => {
        if (item.key == "rowIndex" || item.dataIndex == "action") {
          return true;
        }
        if (this.settingColumns.includes(item.dataIndex)) {
          return true;
        }
        return false;
      });
      this.columns = cols;
    },
    //高级查询方法
    handleSuperQuery(arg) {
      if (!arg) {
        this.superQueryParams = "";
        this.superQueryFlag = false;
      } else {
        this.superQueryFlag = true;
        this.superQueryParams = JSON.stringify(arg);
      }
      this.loadData();
    },
    // 获取查询条件
    getQueryParams() {
      let sqp = {};
      if (this.superQueryParams) {
        sqp["superQueryParams"] = encodeURI(this.superQueryParams);
      }
      var param = Object.assign(sqp, this.queryParam, this.isorter);
      param.field = this.getQueryField();
      param.pageNo = this.ipagination.current;
      param.limit = this.ipagination.pageSize;
      return filterObj(param);
    },
    initDictConfig() {
      initDictOptions("mes_status").then((res) => {
        if (res.success) {
          this.$set(this.dictOptions, "status", res.data);
        }
      });
    },
    clickThenSelect(record) {
      return {
        on: {
          click: () => {
            if(record.id){
              this.rowId = record.id;
              //this.onSelectChange(record.id.split(","), [record]);
            }

          },
        },
      };
    },
    setRowClassName(record){
      return record.id === this.rowId ? 'clickRowStyl' : '';
    },
    onClearSelected() {
      this.selectedRowKeys = [];
      this.selectionRows = [];
      this.selectedMainId = "";
    },
    onSelectChange(selectedRowKeys, selectionRows) {
      this.selectedMainId = selectedRowKeys[0];
      this.selectedRowKeys = selectedRowKeys;
      this.selectionRows = selectionRows;
    },
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error("请设置url.list属性!");
        return;
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1;
      }
      this.onClearSelected();
      var params = this.getQueryParams(); //查询条件
      this.loading = true;
      getAction(this.url.list, params).then((res) => {
        if (res.success) {
          this.dataSource = res.data.records;
          this.ipagination.total = res.data.total;
        }
        if (res.code === 510) {
          this.$message.warning(res.msg);
        }
        this.loading = false;
      });
    },

    // 弹出窗组件
    showDemoModal() {
      this.$refs.modalCompon.modalShow();
    },
    // 点击btn获取数据
    btnGetData(tableName, title) {
      getAction(`${this.url.getColumns}`, {
        tableName: tableName,
      }).then((res) => {
        if (res.code == 0) {
          this.queryInfo = res.data.columns;
          this.title = title;
          this.dictOptions = res.data.dictOptions;
          this.showDemoModal();
        } else {
          this.$message.warning(res.msg);
        }
      });
    },

    //筛选分组
    getGroupTag(arrList) {
      let arr = [];
      var map = {},
        dest = [];
      arrList.forEach((item, index) => {
        if (item.groupTag) {
          arr.push(item);
        }
      });
      for (var i = 0; i < arr.length; i++) {
        var ai = arr[i];
        if (!map[ai.groupTag]) {
          dest.push({
            groupTag: ai.groupTag,
            name: ai.groupName,
            data: [ai],
          });
          map[ai.groupTag] = ai;
        } else {
          for (var j = 0; j < dest.length; j++) {
            var dj = dest[j];
            if (dj.groupTag == ai.groupTag) {
              dj.data.push(ai);
              break;
            }
          }
        }
      }
      this.groupTag = dest;
      console.log(dest);
    },
    showLinkButton(item, record) {
      let btn = new ButtonExpHandler(item.exp, record);
      return btn.show;
    },
    initButtonList() {
      getAction(`${this.url.getColumns}8ac49ec7733bce48017346edef5c00be`).then(
        (res) => {
          console.log("--获取自定义按钮->>", res);
          if (res.success) {
            this.code = res.data.code;
            this.initCgButtonList(res.data.cgButtonList);
            this.initCgEnhanceJs(res.data.enhanceJs);
            this.getGroupTag(res.data.cgButtonList);
          } else {
            this.$message.warning(res.msg);
          }
        }
      );
    },
    initCgEnhanceJs(enhanceJs) {
      //console.log("--onlineList-js增强",enhanceJs)
      if (enhanceJs) {
        let Obj = eval("(" + enhanceJs + ")");
        this.EnhanceJS = new Obj(getAction, postAction, deleteAction);
        this.cgButtonJsHandler("created");
      } else {
        this.EnhanceJS = "";
      }
    },
    initCgButtonList(btnList) {
      let linkArr = [];
      let buttonArr = [];
      if (btnList && btnList.length > 0) {
        for (let i = 0; i < btnList.length; i++) {
          let temp = btnList[i];
          if (temp.buttonStyle == "button") {
            buttonArr.push(temp);
          } else if (temp.buttonStyle == "link") {
            linkArr.push(temp);
          }
        }
      }
      this.cgButtonLinkList = [...linkArr];
      this.cgButtonList = [...buttonArr];
      console.log("链接增强", this.cgButtonLinkList);
    },
    cgButtonJsHandler(buttonCode) {
      if (this.EnhanceJS[buttonCode]) {
        this.EnhanceJS[buttonCode](this);
      }
    },
    cgButtonActionHandler(buttonCode) {
      //处理自定义button的 需要配置该button自定义sql
      if (!this.selectedRowKeys || this.selectedRowKeys.length == 0) {
        this.$message.warning("请先选中一条记录");
        return false;
      }
      if (this.selectedRowKeys.length > 1) {
        this.$message.warning("请只选中一条记录");
        return false;
      }
      let params = {
        formId: this.code,
        buttonCode: buttonCode,
        dataId: this.selectedRowKeys[0],
      };
      console.log("自定义按钮请求后台参数：", params);
      postAction(this.url.buttonAction, params).then((res) => {
        if (res.success) {
          this.loadData();
          this.$message.success("处理完成!");
        } else {
          this.$message.warning("处理失败!");
        }
      });
    },
    cgButtonLinkHandler(record, buttonCode, optType) {
      if (optType == "js") {
        if (this.EnhanceJS[buttonCode]) {
          this.EnhanceJS[buttonCode](this, record);
        }
      } else if (optType == "action") {
        let params = {
          formId: this.code,
          buttonCode: buttonCode,
          dataId: record.id,
        };
        console.log("自定义按钮link请求后台参数：", params);
        postAction(this.url.buttonAction, params).then((res) => {
          if (res.success) {
            this.loadData();
            this.$message.success("处理完成!");
          } else {
            this.$message.warning("处理失败!");
          }
        });
      }
    },
  },
};
</script>
<style scoped>
@import "~@assets/less/common.less";
/deep/.clickRowStyl td{
  background:#00b4ed !important;
}

/deep/.ant-table-tbody.clickRowStyl:hover>td {
  background-color:#00b4ed
}
</style>
